# CalendarOp.py
# AUTHOR: LEWIS MARHIN
# PURPOSE: Handles operation relating to the calendar database of the phone.

__author__ = "Lewis Marhin"
__description__ = "Handles operations relating to the calendar database of the phone."

import calendar
import time
import unittest

now = time.time()
MINUTE = 60
HOUR = 60 * 60
WEEK = 7 * 24 * 60 * 60
MAX_DESC_LENGTH = 24

def addEntry(desc, loc, recur, alarm, startDate, endDate):
    cal = calendar.open()
    newEntry = cal.add_appointment()
    newEntry.content = desc
    newEntry.location = loc
    newEntry.set_time(time.mktime(inDate), time.mktime(outDate))
    newEntry.alarm = alarm
    newEntry.commit()
    
def removeEntry(id):
    cal = calendar.open()
    del cal[event]

def eraseCalendar():
    cal = calendar.open()
    for event in cal:
        removeEntry(event)
    
def getEntry(id):
    cal = calendar.open()
    cal[id] = e
    return str(e.id) + "%" + str(e.content) + "%" + str(e.originating) + "%" + str(e.location) + "%" + str(e.start_time) + "%" + str(e.end_time) + "%" + str(e.get_reapeat())

# These need to be run  in pys60
class ValueCheck(unittest.TestCase):
    global eDesc
    global eLoc
    global eStart
    global eEnd
    global eAlarm
    global eRecursion
    
    eDesc = "Meeting"
    eLoc = "Conference room"
    eStart = time.localtime()
    # Year, Month, Day, Hour, Minute, Second, DayName (0=Mon), DayCount, DST (0=OFF)
    eEnd = (2010, 8, 3, 12, 38, 22, 0, 315, 0)
    eAlarm = time.mktime(eStart) - 300
    eRecursion = 0

    # Check to see if addEntry runs without errors when using valid params
    def testAddEntryNoErrors(self):
        self.assert_(addEntry(eDesc, eLoc, eRecursion, eAlarm, eStart, eEnd))

if __name__ == "__main__":
    unittest.main()